home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / rastpos.c < prev    next >
C/C++ Source or Header  |  1999-02-04  |  7KB  |  233 lines

  1. /* $Id: rastpos.c,v 3.4 1998/07/30 02:40:41 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.0
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: rastpos.c,v $
  26.  * Revision 3.4  1998/07/30 02:40:41  brianp
  27.  * always feedback texture coords, even when texturing disabled
  28.  *
  29.  * Revision 3.3  1998/02/20 04:50:44  brianp
  30.  * implemented GL_SGIS_multitexture
  31.  *
  32.  * Revision 3.2  1998/02/08 20:20:08  brianp
  33.  * added assert.h
  34.  *
  35.  * Revision 3.1  1998/02/02 03:09:34  brianp
  36.  * added GL_LIGHT_MODEL_COLOR_CONTROL (separate specular color interpolation)
  37.  *
  38.  * Revision 3.0  1998/01/31 21:02:29  brianp
  39.  * initial rev
  40.  *
  41.  */
  42.  
  43.  
  44. #ifdef PC_HEADER
  45. #include "all.h"
  46. #else
  47. #include <assert.h>
  48. #include "clip.h"
  49. #include "feedback.h"
  50. #include "light.h"
  51. #include "macros.h"
  52. #include "matrix.h"
  53. #include "mmath.h"
  54. #include "shade.h"
  55. #include "types.h"
  56. #include "xform.h"
  57. #endif
  58.  
  59.  
  60. /*
  61.  * Caller:  context->API.RasterPos4f
  62.  */
  63. void gl_RasterPos4f( GLcontext *ctx,
  64.                      GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  65. {
  66.    GLfloat v[4], eye[4], clip[4], ndc[3], d;
  67.  
  68.    ASSIGN_4V( v, x, y, z, w );
  69.  
  70.    if (ctx->NewModelViewMatrix) {
  71.       gl_analyze_modelview_matrix(ctx);
  72.    }
  73.    if (ctx->NewProjectionMatrix) {
  74.       gl_analyze_projection_matrix(ctx);
  75.    }
  76.    if (ctx->NewTextureMatrix) {
  77.       gl_analyze_texture_matrix(ctx);
  78.    }
  79.  
  80.    /* transform v to eye coords:  eye = ModelView * v */
  81.    TRANSFORM_POINT( eye, ctx->ModelViewMatrix, v );
  82.  
  83.    /* raster color */
  84.    if (ctx->Light.Enabled) {
  85.       GLfloat eyenorm[3];
  86.       TRANSFORM_NORMAL( eyenorm[0], eyenorm[1], eyenorm[2], ctx->Current.Normal,
  87.                         ctx->ModelViewInv );
  88.       if (ctx->Visual->RGBAflag) {
  89.          GLubyte color[4];
  90.          gl_shade_rgba( ctx, 0, 1, &eye, &eyenorm, &color );
  91.          ctx->Current.RasterColor[0] = color[0] * (1.0F / 255.0F);
  92.          ctx->Current.RasterColor[1] = color[1] * (1.0F / 255.0F);
  93.          ctx->Current.RasterColor[2] = color[2] * (1.0F / 255.0F);
  94.          ctx->Current.RasterColor[3] = color[3] * (1.0F / 255.0F);
  95.       }
  96.       else {
  97.      gl_shade_ci( ctx, 0, 1, &eye, &eyenorm, &ctx->Current.RasterIndex );
  98.       }
  99.    }
  100.    else {
  101.       /* use current color or index */
  102.       if (ctx->Visual->RGBAflag) {
  103.          GLfloat *rc = ctx->Current.RasterColor;
  104.          rc[0] = ctx->Current.ByteColor[0] * (1.0F / 255.0F);
  105.          rc[1] = ctx->Current.ByteColor[1] * (1.0F / 255.0F);
  106.          rc[2] = ctx->Current.ByteColor[2] * (1.0F / 255.0F);
  107.          rc[3] = ctx->Current.ByteColor[3] * (1.0F / 255.0F);
  108.       }
  109.       else {
  110.      ctx->Current.RasterIndex = ctx->Current.Index;
  111.       }
  112.    }
  113.  
  114.    /* clip to user clipping planes */
  115.    if (gl_userclip_point(ctx, eye)==0) {
  116.       ctx->Current.RasterPosValid = GL_FALSE;
  117.       return;
  118.    }
  119.  
  120.    /* compute raster distance */
  121.    ctx->Current.RasterDistance =
  122.                       GL_SQRT( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
  123.  
  124.    /* apply projection matrix:  clip = Proj * eye */
  125.    TRANSFORM_POINT( clip, ctx->ProjectionMatrix, eye );
  126.  
  127.    /* clip to view volume */
  128.    if (gl_viewclip_point( clip )==0) {
  129.       ctx->Current.RasterPosValid = GL_FALSE;
  130.       return;
  131.    }
  132.  
  133.    /* ndc = clip / W */
  134.    ASSERT( clip[3]!=0.0 );
  135.    d = 1.0F / clip[3];
  136.    ndc[0] = clip[0] * d;
  137.    ndc[1] = clip[1] * d;
  138.    ndc[2] = clip[2] * d;
  139.  
  140.    ctx->Current.RasterPos[0] = ndc[0] * ctx->Viewport.Sx + ctx->Viewport.Tx;
  141.    ctx->Current.RasterPos[1] = ndc[1] * ctx->Viewport.Sy + ctx->Viewport.Ty;
  142.    ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport.Sz + ctx->Viewport.Tz)
  143.                                / DEPTH_SCALE;
  144.    ctx->Current.RasterPos[3] = clip[3];
  145.    ctx->Current.RasterPosValid = GL_TRUE;
  146.  
  147.    /* FOG??? */
  148.  
  149.    {
  150.       GLuint texSet;
  151.       for (texSet=0; texSet<MAX_TEX_SETS; texSet++) {
  152.          COPY_4V( ctx->Current.RasterMultiTexCoord[texSet],
  153.                   ctx->Current.MultiTexCoord[texSet] );
  154.       }
  155.    }
  156.  
  157.    if (ctx->RenderMode==GL_SELECT) {
  158.       gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
  159.    }
  160.  
  161. }
  162.  
  163.  
  164.  
  165. /*
  166.  * This is a MESA extension function.  Pretty much just like glRasterPos
  167.  * except we don't apply the modelview or projection matrices; specify a
  168.  * window coordinate directly.
  169.  * Caller:  context->API.WindowPos4fMESA pointer.
  170.  */
  171. void gl_windowpos( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  172. {
  173.    /* set raster position */
  174.    ctx->Current.RasterPos[0] = x;
  175.    ctx->Current.RasterPos[1] = y;
  176.    ctx->Current.RasterPos[2] = CLAMP( z, 0.0F, 1.0F );
  177.    ctx->Current.RasterPos[3] = w;
  178.  
  179.    ctx->Current.RasterPosValid = GL_TRUE;
  180.  
  181.    /* raster color */
  182.    if (ctx->Light.Enabled) {
  183.       GLfloat eye[4];
  184.       GLfloat eyenorm[3];
  185.       COPY_4V( eye, ctx->Current.RasterPos );
  186.       if (ctx->NewModelViewMatrix) {
  187.      gl_analyze_modelview_matrix(ctx);
  188.       }
  189.       TRANSFORM_NORMAL( eyenorm[0], eyenorm[1], eyenorm[2],
  190.                         ctx->Current.Normal,
  191.                         ctx->ModelViewInv );
  192.       if (ctx->Visual->RGBAflag) {
  193.          GLubyte color[4];
  194.          gl_shade_rgba( ctx, 0, 1, &eye, &eyenorm, &color );
  195.          ASSIGN_4V( ctx->Current.RasterColor, 
  196.                     (GLfloat) color[0] * (1.0F / 255.0F),
  197.                     (GLfloat) color[1] * (1.0F / 255.0F),
  198.                     (GLfloat) color[2] * (1.0F / 255.0F),
  199.                     (GLfloat) color[3] * (1.0F / 255.0F) );
  200.       }
  201.       else {
  202.      gl_shade_ci( ctx, 0, 1, &eye, &eyenorm, &ctx->Current.RasterIndex );
  203.       }
  204.    }
  205.    else {
  206.       /* use current color or index */
  207.       if (ctx->Visual->RGBAflag) {
  208.          ASSIGN_4V( ctx->Current.RasterColor,
  209.                     ctx->Current.ByteColor[0] * (1.0F / 255.0F),
  210.                     ctx->Current.ByteColor[1] * (1.0F / 255.0F),
  211.                     ctx->Current.ByteColor[2] * (1.0F / 255.0F),
  212.                     ctx->Current.ByteColor[3] * (1.0F / 255.0F) );
  213.       }
  214.       else {
  215.      ctx->Current.RasterIndex = ctx->Current.Index;
  216.       }
  217.    }
  218.  
  219.    ctx->Current.RasterDistance = 0.0;
  220.  
  221.    {
  222.       GLuint texSet;
  223.       for (texSet=0; texSet<MAX_TEX_SETS; texSet++) {
  224.          COPY_4V( ctx->Current.RasterMultiTexCoord[texSet],
  225.                   ctx->Current.MultiTexCoord[texSet] );
  226.       }
  227.    }
  228.  
  229.    if (ctx->RenderMode==GL_SELECT) {
  230.       gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
  231.    }
  232. }
  233.